/*企业Id*/
var siteid = "kf_9151";
/*应答客服组id，在客户端生成代码界面创建*/
var settingid = "kf_9151_1463446736150";
var uid = getCookieValueForXn('SHOP_id') || "";
var uname = getCookieValueForXn('SHOP_niceName') || "";
var sign = getCookieValueForXn('SHOP_mqklxnxn') || "";
var isvip = 0;
var userlevel = "";
var web_chat_param = {siteid : siteid, uid: uid, settingid:settingid, uname: uname};
var webChat = {
		/*提交订单*/
		submit_order : function(orderid, orderprice){
			web_chat_param.settingid = settingid;
			web_chat_param.orderid = orderid;
			web_chat_param.orderprice = orderprice;
		},
		/*订单确认*/
		confir_order : function(ntalkerparam){
			web_chat_param.settingid = settingid;
			web_chat_param.ntalkerparam = ntalkerparam;
		},
		/*购物车*/
		cart : function(ntalkerparam){
			web_chat_param.settingid = settingid;
			web_chat_param.ntalkerparam = ntalkerparam;
		},
		/*列表页*/
		item_page : function(ntalkerparam){
			web_chat_param.settingid = settingid;
			web_chat_param.ntalkerparam = ntalkerparam;
		},
		/*商品详情页*/
		product_detail : function(ntalkerparam){
			web_chat_param.settingid = settingid;
			web_chat_param.ntalkerparam = ntalkerparam;
		},
		/*支付成功页*/
		pay_success : function(orderid){
			web_chat_param.settingid = settingid;
			web_chat_param.orderid = orderid;
		}
}
$(function(){
	$(".col-contact .contact-btn").removeAttr("target");
	$(".col-contact .contact-btn").attr("href", "javascript:;");
	$(".col-contact .contact-btn").on('click',function(){
		if(!checklogin()){
			loginiframe();
		} else{
			var protocol = "https:" == location.protocol ? "https://" : "http://";
			$.get(protocol + 'dl.ntalker.com/js/xn6/ntkfstat.js?siteid=kf_9151', function(){
				NTKF.im_openInPageChat();
			}, 'script');
		}
	});
	var len = $(".fixed-layer .service").length;
	if(len > 0){
		$(".fixed-layer .service").removeAttr("target");
		$(".fixed-layer .service").attr("href", "javascript:;");
		$(".fixed-layer .service").on('click',function(){
			if(!checklogin()){
				loginiframe();
			} else{
				var protocol = "https:" == location.protocol ? "https://" : "http://";
				$.get(protocol + 'dl.ntalker.com/js/xn6/ntkfstat.js?siteid=kf_9151', function(){
					NTKF.im_openInPageChat();
				}, 'script');
			}
		});
	}
});

function getCookieValueForXn(cookiename){
	var cookiestring = document.cookie;
	var start = cookiestring.indexOf(cookiename + '=');
	if (start == -1)   //   找不到
	return   null;
	start += cookiename.length   +   1;
	var end = cookiestring.indexOf( "; ",   start);
	if (end == -1) return decodeURIComponent(cookiestring.substring(start));
	return decodeURIComponent(cookiestring.substring(start, end));
}
function checklogin(){
	var cookie_value = getcookie('SHOP_id'); // 读取 cookie
	cookie_value = cookie_value || "";
	if(cookie_value == null || "" == cookie_value || "null" == cookie_value){
		return false;
	} 
	return true;
}